<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.logo{margin-left: 150px;margin-top: 30px;}
		#box{width: 988px;border:1px solid #fdfdfd;box-shadow: 0px 5px 5px 5px #888;
			margin: 20px auto;overflow: hidden;padding: 20px;}
		#box form{float: left;}
		
		#box  h1 a{font:12px/46px "";color: #0083CE;}
		#box  h1.hy{display: inline-block;margin-right:30px ;font:16px/46px "";}
		#box  h1.er{display: inline-block;font:12px/46px ""}
		#box form input{display: block;}
		#user ,#pass,#nikename{width: 338px; height: 38px; border: 1px solid #0083CE;margin-bottom: 30px;}
		#btn{width: 326px;height: 36px;border: none; border-bottom: 1px solid #0083CE;background: #0099f1;}
		#box img{float: right;}
		</style>
	</head>
	<body>
		<img src="images/logo_02.png" class="logo"/>
		<div id="box">
		<form enctype="multipart/form-data">
		 	<h1 class="hy">请您注册</h1>
		 	<h1 class="er">已有账号<a href="l.html">去登录</a></h1>
		<!--<h1>注册页面<a href="l.html">去登录</a></h1>-->
	    
		<input type="text" id="user" placeholder="请输入用户名">
	    <input type="text" id="nikename" placeholder="请输入昵称">
	
	    <input type="text" id="pass" placeholder="请输入密码">
	    <input type="button" value="注册" id="btn" >
	    <span id="msg"></span>
	    </form>
	    <img src="images/reg.png"/>
		</div>
	    
	    
	    
	</body>
	<script type="text/javascript" src="libs/jquery.js"></script>
	<script type="text/javascript">
		class Register{
				constructor(){
					this.url = "api/reg";
					this.init();
					
				}
			

			
		init(){
			console.log(this.url);
				var that = this;
				$("#btn").click(function(){
					that.load()
				})
			}


			load(){
				$.ajax({
					url:this.url,
					type:"post",
					data:{
						username:$("#user").val(),
						password:$("#pass").val(),
						nikename:$("#nikename").val()
					},
					success:function(res){
						switch(res.error){
							case 1:
								$("#msg").html(res.msg)
								break;
							case 0:
								$("#msg").html(res.msg+'三秒后去往登录页面')
								setTimeout(()=>{
									location.href="l.html"
								},3000)
								break;
							case 3:
								$("#msg").html(res.msg)
								//that.display();
								break;
							default :
							 	$("#msg").html(res.msg)
						}
					}
				})
			}
			diaplay(){
				console.log(this.res);
			}
		}
		new Register();
	</script>
</html>
